package model;

import java.util.HashMap;
import java.util.Map;

public class UserRepository implements IRepository<User> {
	
//	protected static UserRepository instance;
	protected static Integer idCount = 1;
	
	protected Map<Integer, User> data;
	
	public UserRepository(){
		this.data = new HashMap<Integer, User>();
	}
	
//	public static UserRepository getInstance(){
//		if(instance == null){
//			instance = new UserRepository();
//		}
//		return instance;
//	}
	
	@Override
	public void save(User user) {
		if(user.getId() == null){
			user.setId(idCount++);
		}
		this.data.put(user.getId(), user);
	}

	@Override
	public void delete(User user) {
		this.data.remove(user.getId());
	}

	@Override
	public User find(Integer id) {
		return this.data.get(id);
	}

}
